#!/usr/bin/python


# Ideas for hexagonal board.

jugadores = { 0 : "A" , 1 : "Mati", 2 : "Santi" }
unidades = { "peon" : 0, "soldier" : 1 }

class Unit():
	 
	def __init__(self, owner):
		 self.owner = owner
		 
	def __str__(self):
		return "%s'sU" % ( jugadores[self.owner] )
	
class Peon(Unit):
	
	def __str__(self):
		return "%s'sP" % ( jugadores[self.owner] )
	
class Soldier(Unit):
	
	def __str__(self):
		return "%s'sS" % ( jugadores[self.owner] )

class Casillero():
	
	def __init__(self):
		self.contenido = None
		
	def __str__(self):
		return "( %s )" % ( str(self.contenido) )






class Board():
	
	def __init__(self,dim = 5):
		
		self.borde = 2*dim-1
		self.grid = []
		for i in xrange(0,self.borde):
			self.grid.append([])
			if ( i % 2 == 0 ):
				for j in xrange(0,self.borde):
					self.grid[i].append(Casillero())
			else:
				for j in xrange(0,self.borde-1):
					self.grid[i].append(Casillero())
					
					
	def __str__(self):
		
		rta = '\n'
		for i in xrange(0,self.borde):
			if ( i % 2 == 0 ):
				rta += ' '
				for j in xrange(0,self.borde):
					rta += str(self.grid[i][j])+' '
			else:
				rta += '     '
				for j in xrange(0,self.borde-1):
					rta += str(self.grid[i][j])+' '
			rta+='\n'
			
		
		return rta
				
	def create_unit(self,x,y,obj_type,owner):
		obj_type_code = unidades[obj_type.lower()]
		if ( obj_type_code == 0 ):
			self.grid[x][y].contenido = Peon(owner)
		elif (obj_type_code == 1):
			self.grid[x][y].contenido = Soldier(owner)
		else:
			print "Error creating Unit: %s is not a valid object type" % obj_type
		
		
if( __name__ == "__main__" ):
	board = Board(6)
	board.create_unit(2,2,"PeOn",0)
	print "Test:"
	print board